package com.platform.controller;

import com.platform.entity.VersionEntity;
import com.platform.service.VersionService;
import com.platform.utils.PageUtils;
import com.platform.utils.Query;
import com.platform.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 版本
 *
 */
@RestController
@RequestMapping("/version")
public class VersionController {
    @Autowired
    private VersionService versionService;

    /**
     * 查看列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("version:list")
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<VersionEntity> tagList = versionService.queryList(query);
        int total = versionService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(tagList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    /**
     * 查看信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("version:info")
    public R info(@PathVariable("id") Integer id) {
        VersionEntity tag = versionService.queryObject(id);

        return R.ok().put("version", tag);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("version:save")
    public R save(@RequestBody VersionEntity tag) {
        int i = versionService.save(tag);
        if (i > 0) {
            return R.ok();
        } else {
            return R.error("添加失败");
        }
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("version:update")
    public R update(@RequestBody VersionEntity tag) {
        versionService.update(tag);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("version:delete")
    public R delete(@RequestBody Integer[] ids) {
        versionService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<VersionEntity> list = versionService.queryList(params);

        return R.ok().put("list", list);
    }
}
